#ifndef __COMMON_H__
#define __COMMON_H__
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#include <string.h>
#include "macro.h"
#include "config.h"
#include "interface.h"

#define ANSI_FG_BLACK   "\33[1;30m"
#define ANSI_FG_RED     "\33[1;31m"
#define ANSI_FG_GREEN   "\33[1;32m"
#define ANSI_FG_YELLOW  "\33[1;33m"
#define ANSI_FG_BLUE    "\33[1;34m"
#define ANSI_FG_MAGENTA "\33[1;35m"
#define ANSI_FG_CYAN    "\33[1;36m"
#define ANSI_FG_WHITE   "\33[1;37m"
#define ANSI_BG_BLACK   "\33[1;40m"
#define ANSI_BG_RED     "\33[1;41m"
#define ANSI_BG_GREEN   "\33[1;42m"
#define ANSI_BG_YELLOW  "\33[1;43m"
#define ANSI_BG_BLUE    "\33[1;44m"
#define ANSI_BG_MAGENTA "\33[1;35m"
#define ANSI_BG_CYAN    "\33[1;46m"
#define ANSI_BG_WHITE   "\33[1;47m"
#define ANSI_NONE       "\33[0m"

#define DEVICE_BASE 0xa0000000
#define MMIO_BASE 0xa0000000

#define SERIAL_PORT     (DEVICE_BASE + 0x00003f8)
#define KBD_ADDR        (DEVICE_BASE + 0x0000060)
#define RTC_ADDR        (DEVICE_BASE + 0x0000048)
#define VGACTL_ADDR     (DEVICE_BASE + 0x0000100)
#define AUDIO_ADDR      (DEVICE_BASE + 0x0000200)
#define DISK_ADDR       (DEVICE_BASE + 0x0000300)
#define FB_ADDR         (MMIO_BASE   + 0x1000000)
#define AUDIO_SBUF_ADDR (MMIO_BASE   + 0x1200000)


#define ANSI_FMT(str, fmt) fmt str ANSI_NONE
#define FMT_WORD "0x%016" PRIx64
#define FMT_PADDR "0x%016" PRIx64

#define Log(fmt,...) if(!silent) printf(ANSI_FMT(fmt,ANSI_FG_YELLOW)"\n", ##__VA_ARGS__)
#define LogErr(fmt,...) printf(ANSI_FMT(fmt,ANSI_FG_RED)"\n", ##__VA_ARGS__)
#define panic(...) if(!silent) printf( __VA_ARGS__)
#define REG_FMT "%-3s:0x%016lx\t"
typedef uint64_t vaddr_t;
typedef uint64_t paddr_t;
typedef uint64_t word_t;
#endif